package com.example.studyroom.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.studyroom.Entity.StudyRoom;
import com.example.studyroom.dto.StudyRoomAdmin.RoomAdminDTO;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface StudyRoomMapper extends BaseMapper<StudyRoom> {

    @Select("SELECT * FROM StudyRoom")
    List<StudyRoom> getAllStudyRooms();

    @Insert("INSERT INTO StudyRoom (roomName, capacity, facilities) VALUES (#{roomName}, #{capacity}, #{facilities})")
    void addStudyRoom(StudyRoom studyRoom);

    @Delete("DELETE FROM StudyRoom WHERE id = #{id}")
    void deleteStudyRoom(Integer id);

    //修改自习室信息
    @Update("UPDATE StudyRoom SET roomName = #{roomName}, adminName = #{adminName}, " +
            "capacity = #{capacity}, facilities = #{facilities} WHERE id = #{id}")
    void modifyStudyRoom(StudyRoom studyRoom);

    //查看该管理员管理的自习室
    @Select("SELECT * FROM StudyRoom WHERE adminName = #{adminName}")
    List<RoomAdminDTO> findByAdminName(@Param("adminName") String adminName);

    //根据自习室名称查找自习室
    @Select("SELECT * FROM StudyRoom WHERE roomName = #{roomName}")
    StudyRoom findByRoomName(String roomName);
    //更新剩余座位数量
    @Update("UPDATE StudyRoom SET capacity = #{capacity} WHERE roomName = #{roomName}")
    void updateCapacity(StudyRoom studyRoom);

    //修改负责的管理员
    @Update("UPDATE StudyRoom SET adminName = #{adminName} WHERE roomName = #{roomName}")
    void updateRoomAdmin(StudyRoom studyRoom);
}
